package com.zsc.shixun.service.function.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zsc.shixun.entity.Article;
import com.zsc.shixun.entity.CollectCategories;
import com.zsc.shixun.model.unauthorize.blogger.BloggerVO;
import com.zsc.shixun.service.IArticleService;
import com.zsc.shixun.service.ICollectCategoriesService;
import com.zsc.shixun.service.IUserService;
import com.zsc.shixun.service.function.BloggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 博主
 * </p>
 *
 * @author ZWYZY
 * @since 2020/6/20
 */
@Service
@Transactional
public class BloggerServiceImpl implements BloggerService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private IArticleService articleService;
    @Autowired
    private IUserService userService;
    @Autowired
    private ICollectCategoriesService collectCategoriesService;

    @Override
    public BloggerVO getBlogger(Long id) {
        BloggerVO bloggerVO = new BloggerVO();
        bloggerVO.setUser(userService.getById(id));
        bloggerVO.setArticleList(articleService.list(new QueryWrapper<Article>().lambda().eq(Article::getUserId, id).orderByDesc(Article::getCreateTime)));
        bloggerVO.setCollectCategoriesList(collectCategoriesService.list(new QueryWrapper<CollectCategories>().lambda().eq(CollectCategories::getUserId, id).eq(CollectCategories::getIsShow, 1)));

        return bloggerVO;
    }
}
